package math;

public class LogicalBooleanVariable implements BooleanExpression {

  private String name;
  
  private BooleanExpression value;
  
  public LogicalBooleanVariable(String name){
    this.name = name;
  }
  
  public void bind(BooleanExpression value){
    this.value = value;
  }
  
  @Override
  public int countMembers() {
    return 1;
  }
  
  public String getName() {
    return name;
  }

  public BooleanExpression getValue() {
    return value;
  }

  public boolean isBound(){
    return value != null;
  }

  @Override
  public boolean matches(Expression expr) {
    if (isBound()){
      return value.matches(expr);
    } else {
      if (expr instanceof BooleanExpression){
        bind((BooleanExpression) expr);
        return true;
      } else
        return false;
    }
  }

  public void reset() {
    value = null;
  }

  @Override
  public String toString() {
    return "@" + name + "=" + value;
  }

  @Override
  public <R> R accept(ExpressionVisitor<R> visitor) {
    return visitor.visitLogicalBooleanVariable(this);
  }

  @Override
  public Expression simplify() {
    return this;
  }

  @Override
  public BooleanExpression toDNF() {
    return this;
  }
}